<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

      <table class="merge_results">
        <thead>
          <tr class="result">
            <th>{{#t}}User{{/t}}</th>
            <td><%= user.name %></td>
            <td><%= other_user.name %></td>
          </tr>
        </thead>
        <tbody>
          <tr class="result">
            <th>{{#t}}Action{{/t}}</th>
            <td>{{#t}}will be deleted{{/t}}</td>
            <td>{{#t}}will be kept{{/t}}</td>
          </tr>
          <tr class="result">
            <th>{{#t}}Emails{{/t}}</th>
            <td>{{#t}}no emails{{/t}}</td>
            <td>
                <% emails = Canvas::ICU.collate((user.communication_channels.unretired.email + other_user.communication_channels.unretired.email).map(&:path).uniq) %>
                <% if emails.empty? %>
                {{#t}}no emails{{/t}}
                <% else %>
                  <ul class="unstyled_list">
                    <% emails.each do |email| %>
                      <li><%= email %></li>
                    <% end %>
                  </ul>
                <% end %>
            </td>
          </tr>
          <tr class="result">
            <th>{{#t}}Logins{{/t}}</th>
            <td>{{#t}}no logins{{/t}}</td>
            <td>
              <% pseudonyms = Canvas::ICU.collate_by(user.pseudonyms.active + other_user.pseudonyms.active, &:unique_id) %>
              <% if pseudonyms.empty? %>
                {{#t}}no logins{{/t}}
              <% else %>
                <table>
                  <% pseudonyms.each do |pseudonym| %>
                    <tr>
                      <td><%= pseudonym.unique_id %></td>
                      <td><%= pseudonym.account.name %></td>
                    </tr>
                  <% end %>
                </table>
              <% end %>
            </td>
          </tr>
          <tr class="result">
            <th>{{#t}}Enrollments{{/t}}</th>
            <td>{{#t}}no enrollments{{/t}}</td>
            <td>
              <% enrollments = (user.enrollments.current + other_user.enrollments.current).sort_by{|e| [e.state_sortable, e.rank_sortable, Canvas::ICU.collation_key(e.course.name)] } %>
              <% if enrollments.empty? %>
                {{#t}}no enrollments{{/t}}
              <% else %>
                <table>
                  <% enrollments.each do |enrollment| %>
                    <tr>
                      <td><%= enrollment.course.name %></td>
                      <td><%= enrollment.readable_type %></td>
                    </tr>
                  <% end %>
                </table>
              <% end %>
            </td>
          </tr>
        </tbody>
      </table>
